DEBUG_MODE = true
BASE_PATH = 'http://localhost:10000/'
fs = require 'fs'

indexData = {}
fs.readFile "./data/articles.json", 'utf8', (err, data) ->
  if err
    console.log err
    return 
  trim = /[\n\r\t]/g
  indexData.articlesData = JSON.parse data.replace trim, ''


module.exports = 
  index : (req, res) ->
    res.render 'index', {
      basePath : BASE_PATH
      title : '每天再往前一点！'
      debug : DEBUG_MODE
      cssFileArr : []
      jsFileArr : []
      pageData : {
        articles : indexData.articlesData
      }
    }
  base : (req, res) ->
    res.render 'base', {
      basePath : BASE_PATH
      title : '每天再多写一点！'
      debug : DEBUG_MODE
      cssFileArr : []
      jsFileArr : []
    }
  article : (req, res) ->
    res.render 'article', {
      basePath : BASE_PATH
      title : '每天再多看一点！'
      debug : DEBUG_MODE
      pageData : indexData.articlesData[req.params.id or 0]
      cssFileArr : []
      jsFileArr : []
    }
